//
//  BVLoginViewController.m
//  AFNetworking
//
//  Created by 崔晋 on 2019/8/20.
//

#import "BVLoginViewController.h"
#import "BVUIBizKitUtil.h"
#import "BVPhoneLoginViewController.h"
#import "WXApi.h"

@interface BVLoginViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *backImageView;

@end

@implementation BVLoginViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self setupViews];
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wechatLoginSuccess:) name:BV_WECHAT_LOGIN_NEED_BIND_PHONE_NOTIFICATION_KEY object:nil];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


- (void)wechatLoginSuccess:(NSNotification *)sender {
    NSString *uniId = sender.object;
    BVPhoneLoginViewController *loginPhone = [[BVPhoneLoginViewController alloc] initWithNibName:@"BVPhoneLoginViewController" bundle:[BVBundle bundleWithClass:[self class] name:BV_BUNDLE_USER_LOGIN_SCENE_MODULE]];
    loginPhone.unionid = uniId;
    [self.navigationController pushViewController:loginPhone animated:YES];
}

- (IBAction)loginWechat:(UIButton *)sender {
    [WXApi startLogByLevel:WXLogLevelDetail logBlock:^(NSString * _Nonnull log) {
        NSLog(@"%@", log);
    }];
    SendAuthReq *request = [[SendAuthReq alloc] init];
    request.scope = @"snsapi_userinfo";
    request.state = @"123";
    [WXApi sendReq:request completion:^(BOOL success) {
        
    }];
}

- (IBAction)loginPhone:(UIButton *)sender {
    BVPhoneLoginViewController *loginPhone = [[BVPhoneLoginViewController alloc] initWithNibName:@"BVPhoneLoginViewController" bundle:[BVBundle bundleWithClass:[self class] name:BV_BUNDLE_USER_LOGIN_SCENE_MODULE]];
    [self.navigationController pushViewController:loginPhone animated:YES];
}

- (IBAction)agreeClick:(UIButton *)sender {
    
}

- (void)setupViews {
    UIImage *backgroundImage = [BVUIBizKitUtil commonImageWithName:@"background_image"];
    self.backImageView.image = backgroundImage;
}


@end
